package com.kob.backend.controller.user.account;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.generator.config.querys.MariadbQuery;
import com.kob.backend.mapper.UserMapper;
import com.kob.backend.pojo.User;
import com.kob.backend.service.user.account.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.embedded.undertow.UndertowWebServer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author cyz
 * @version 1.0
 * @date 2023/1/12 21:38
 */
@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @Autowired
    private UserMapper userMapper;

    @PostMapping("/user/account/token/")
    public Map<String, String> getToken(@RequestParam Map<String, String> map) {
        String username = map.get("username");
        String password = map.get("password");
        String typename = map.get("type");
        int errCode;
        int type;
        if (typename.equals("管理员用户")){
            type = 1;
        }else if (typename.equals("基站用户")){
            type = 2;//rsu
        }else {
            type = 3;//ev
        }
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        User user = userMapper.selectOne(wrapper);
        if (type == user.getType()){
            errCode=1;//正确
        }else{
            errCode=0;//错误
        }

        return loginService.getToken(username, password,errCode);
    }
}
